const app = getApp()
Page({
  data: {
    order: {},
    role: "normal",
    costTypeIndex: 0,
    costType: 1,
    costArray: [
      {
        id: '1',
        name: '修理费'
      },
      {
        id: '2',
        name: '加油费'
      },
      {
        id: '3',
        name: '其他费用'
      }
    ]
  },
  onLoad: function (option) {
    var openId = app.globalData.openId;
    var account = wx.getStorageSync(openId);
    const order = JSON.parse(option.order);
    this.setData({
      order: order,
      role: account.role
    });
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    var order = this.data.order;
    order.transferDate = e.detail.value;
    this.setData({
      order: order
    })
  },
  costTypeChnage: function (e) {
    console.log('支出类型发送选择改变，携带值为', e.detail.value)
    var cType = this.data.costArray[e.detail.value].id;
    this.setData({
      costTypeIndex: e.detail.value,
      costType: cType
    })
  },
  formSubmit: function (e) {
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
    const order = e.detail.value;
    order.orderId = this.data.order.orderId;
    order.price = 0;
    order.weight = 0;
    order.type = this.data.costType;
    order.updater = app.globalData.openId;
    wx.request({
      url: app.globalData.baseUrl + 'order/updateOrder', //仅为示例，并非真实的接口地址
      data: order,
      method: "POST",
      success: function (res) {
        if(res.data.code==0){
         wx.navigateBack({
           complete:function(){
             wx.showToast({
               title: "修改支出成功",
               icon: "success"
             });
           }
         });
        }else{
          wx.showToast({
            title: "修改支出失败",
            icon: "fail"
          })
        }
      }
    });
  },
  formReset: function () {
    console.log('form发生了reset事件')
  }
});